function read_db_info_js(id, csrf_token, tab) {
    data = {'db_id': id};
    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/v0/tableinfo',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                $('#'+tab).empty();
                $('#'+tab).append("<option>--请选择表--</option>");
                for (var i=0;i<result.data.length;i++){
                    $('#'+tab).append("<option  value='"+result.data[i].id+"'>"+result.data[i].table_name+"</option>");
            }

        }
        }
})
}


function read_column_info_js(id, csrf_token, tab) {
    data = {'table_id': id};
    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/v0/columninfo',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                $('#'+tab).empty();
                    $.ajax({
                        beforeSend: function (xhr, settings){
                            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                                xhr.setRequestHeader("X-CSRFToken", csrf_token);
                            }
                        },
                        type: 'get',
                        url: '/api/v0/dbinfo',
                        contentType: 'application/json',
                        success: function (dbresult) {
                            if (dbresult) {
                                var dbresult = JSON.parse(dbresult);
                                for (var i = 0; i < result.data.length; i++) {
                                    var html = "<label>" + result.data[i].column_name + "</label>";
                                    html += "<select name='dbid' id='dbid' onchange='read_db_info_js'this.options[this.options.selectedIndex].value', " + csrf_token + ",tableid>";
                                    html += "<option>--请选择数据库--</option>";

                                    for (var db_i = 0; db_i < dbresult.data.length; db_i++) {
                                        var option_str = "<option value=" + dbresult.data[db_i].id + ">" + dbresult.data[db_i].db_name + "</option>";
                                        html += option_str

                                    }
                                    html += '</select>';


                                    html += "<select name='tableid' id='tableid' onchange='read_db_info_js'this.options[this.options.selectedIndex].value', " + csrf_token + ",columnid></select><br><br>";

                                    $('#' + tab).append(html);

                                }

                            }
                        }
                    });

            }

        }
})
}


function read_index_info_category(id, db_id, csrf_token) {
    data = {'category_id': Number(id), 'db_id': Number(db_id)};

    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/v0/columninfo',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                $('#indexid').empty();
                $('#indexid').append("<option>--请选择属性--</option>");
                for (var i=0;i<result.data.length;i++){
                    $('#indexid').append("<option  value='"+result.data[i].id+"'>"+result.data[i].column_name+"</option>");
            }

        }
        }
})
}


function read_data_type_by_db_driver_js(id, csrf_token) {
    data = {'db_driver_id': Number(id)};

    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/v0/data_type_info',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                $('#datatype').empty();
                $('#datatype').append("<option>--数据类型--</option>");
                for (var i=0;i<result.data.length;i++){
                    $('#datatype').append("<option  value='"+result.data[i].id+"'>"+result.data[i].data_type_name+"</option>");
            }

        }
        }
})
}



function read_table_by_db_js(id, csrf_token) {
    data = {'db_id': Number(id)};

    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/v0/tableinfo',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                $('#table').empty();
                $('#table').append("<option value='0'>--表--</option>");
                for (var i=0;i<result.data.length;i++){
                    $('#table').append("<option  value='"+result.data[i].id+"'>"+result.data[i].table_name+"</option>");
            }

        }
        }
})
}

